home *** CD-ROM | disk | FTP | other *** search
- ' This routine by Bud Aaron
- ' Small Packages, 4052 Johnson Drive, Oceanside CA 92056
- ' (619) 724-4840 is hereby placed in public domain
- ' for all to use in whatever way they choose.
- '
- ' If you find problems, please give me a call
- Function Coerce (Value As Currency, Places As Long)
- Dim DecimalPart As Currency
- Dim Factor As Integer
-
- If Places = 1000 Then Value = Value * .001
- If Places = 1000000 Then Value = Value * .000001
-
- DecimalPart = Value - Int(Value)
- Select Case Places
- Case 0 ' Dollar coercion with rounding
- Factor = 1
- GoSub RoundIt
- Case 1 ' Tenths (1 decimal place) coercion
- Factor = 10
- GoSub RoundIt
- Case 2 ' Hundredths (2 decimal place) coercion
- Factor = 100
- GoSub RoundIt
- Case 3 ' Thousandths (3 decimal place) coercion
- Factor = 1000
- GoSub RoundIt
- Case 1000 ' Coerce to Thousands with rounding
- Factor = 1
- GoSub RoundIt
- Case 1000000 ' Coerce to Millions with rounding
- Factor = 1
- GoSub RoundIt
- End Select
- Exit Function
-
- RoundIt:
- DecimalPart = DecimalPart * Factor
- If DecimalPart - Int(DecimalPart) >= .5 Then
- DecimalPart = DecimalPart + 1
- End If
-
- DecimalPart = Int(DecimalPart) / Factor
- Value = Int(Value) + DecimalPart
- Return
- End Function
-
-